//
//  WeiboCommentModel.m
//  微blog
//
//  Created by Jorn.Wu on 15/8/29.
//  Copyright (c) 2015年 Jorn.Wu(jorn_wza@sina.com). All rights reserved.
//

#import "WeiboCommentModel.h"
#import "NSString+Extension.h"
#import "RegexKitLite.h"

@implementation WeiboCommentModel

- (void)setAttributes:(NSDictionary *)dataDic {
    [super setAttributes:dataDic];
    
    NSDictionary *userDic = [dataDic objectForKey:@"user"];
    UserModel *user = [[UserModel alloc] initWithDataDic:userDic];
    self.userModel = user;
    
    NSDictionary *status = [dataDic objectForKey:@"status"];
    HomeWeiboModel *weibo = [[HomeWeiboModel alloc] initWithDataDic:status];
    self.weiboModel = weibo;
    
    NSDictionary *commentDic = [dataDic objectForKey:@"reply_comment"];
    if (commentDic != nil) {        //原评论
        WeiboCommentModel *sourceComment = [[WeiboCommentModel alloc] initWithDataDic:commentDic];
        self.sourceCommentModel = sourceComment;
    }
    
    
    /**
     * 处理评论中的表情文字
     */
    self.text = [NSString stringByEmotionRegexHandleFromString:_text];
    
    /**
  /Users/Jorn.Wu/Jorn/UI课后作业/微blog/微blog/Class/Home(首页)/Model/WeiboCommentModel.m   * 对来源文字解析
     */
    if (self.source != nil) {
        NSString *regex = @">.+<";  //>新浪 weibo.com<
        NSArray *items = [self.source componentsMatchedByRegex:regex];
        
        if (items.count != 0) {
            NSString *temp = items[0];      //其实只有一个
            temp = [temp substringWithRange:NSMakeRange(1, temp.length - 2)];
            self.source = [NSString stringWithFormat:@"来自:%@",temp];
        }
    }
    
    
}


@end
